import wx

class MainFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(500, 300))

        # 显示按钮功能
        self.button_ok = wx.Button(self, -1, "OK", pos=(20, 20), size=(60, 30))
        self.Bind(wx.EVT_BUTTON, self.OnClick, self.button_ok)

        self.button_cancel = wx.Button(self, -1, "Cancel", pos=(20, 80), size=(60, 30))
        self.Bind(wx.EVT_BUTTON, self.OnClick, self.button_cancel)

    def OnClick(self, event):
        if event.GetEventObject() == self.button_ok:
            print("{}".format(event.GetEventObject().GetLabel()))
        elif event.GetEventObject() == self.button_cancel:
            print("{}".format(event.GetEventObject().GetLabel()))
        else:
            print("No Button")


class App(wx.App):
    def __init__(self):

        super(self.__class__, self).__init__()
        # wx.App.__init__(self)
        self.title = None
        self.version = None

    def OnInit(self):
        self.version = "lesson_3：button"
        self.title = "wxPython初级教程之" + self.version
        frame = MainFrame(None, -1, self.title)
        frame.Show(True)

        return True

if __name__ == "__main__":
    app = App()
    app.MainLoop()  # 启动主事件循环后，持续检查是否有事件需要处理，处理事件并更新界面，直到应用程序关闭。
